﻿/**
 * Peter
 * Created by: Peter Development Team
 *    http://peter.codeplex.com/
 * 
 * GNU General Public License version 2 (GPLv2)
 *    http://peter.codeplex.com/license
 *
 *  This code is provided on an AS IS basis, with no WARRANTIES,
 *  CONDITIONS or GUARANTEES of any kind.
 *
 **/

using System.ComponentModel.Composition;
using Peter.Common.Dialog;
using Peter.Common.Interfaces;

namespace Peter.Common.Services
{
   /// <summary>
   /// Service used to show request for passwords.
   /// </summary>
   [Export (typeof (IPasswordRequestService))]
   [PartCreationPolicy (CreationPolicy.Shared)]
   public class PasswordRequestService : IPasswordRequestService
   {
      /// <summary>
      /// Gets or Sets the peter reference.
      /// </summary>
      [Import (typeof (IPeter))]
      public IPeter Peter { get; set; }

      /// <summary>
      /// Requests the user to input a password.
      /// </summary>
      /// <param name="passwordFor">Additional string for password.</param>
      /// <returns>The user's password.</returns>
      public string RequestPassword (string passwordFor = null)
      {
         var model = new ModelPasswordRequest { PasswordFor = passwordFor, Title = "Password Request"};
         var res = Peter.ShowDialog (model);
         if (res == DialogCloseAction.Ok)
            return model.Password;
         return string.Empty;
      }
   }

   /// <summary>
   /// Interface for password request service.
   /// </summary>
   public interface IPasswordRequestService
   {
      /// <summary>
      /// Requests the user to input a password.
      /// </summary>
      /// <param name="passwordFor">Additional string for password.</param>
      /// <returns>The user's password.</returns>
      string RequestPassword (string passwordFor = null);
   }
}
